package com.lyz.myself;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.util.unit.DataSize;

import javax.servlet.MultipartConfigElement;

/*@SpringBootApplication 等价于以默认属性使用 @Configuration ， @EnableAutoConfiguration 和 @ComponentScan， 所以启动类无需再添加这三个注解
@Configuration ： 标注一个类为配置类。
@EnableAutoConfiguration ：开启自动配置。
@ComponentScan ：自动收集所有的 Spring 组件*/
@EnableTransactionManagement
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@MapperScan("com.lyz.myself.mapper")
public class MyselfApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(MyselfApplication.class, args);
    }

    /*如果需要通过打包的方式在web容器中进行部署，则需要继承 SpringBootServletInitializer
    覆盖configure(SpringApplicationBuilder)方法*/
    @Override
    protected SpringApplicationBuilder  configure(SpringApplicationBuilder builder) {
        // 注意这里要指向原先用main方法执行的Application启动类
        return builder.sources(MyselfApplication.class);
    }
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //单个文件最大
        factory.setMaxRequestSize(DataSize.ofKilobytes(1000000));
        return factory.createMultipartConfig();
    }

}
